package com.SiLa.LispPlugin;

import com.SiLa.LispPlugin.psi.LispTypes;
import com.intellij.lexer.FlexAdapter;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;

import java.io.Reader;
import java.util.HashMap;
import java.util.Map;

public class LispSyntaxHighlighter extends SyntaxHighlighterBase {
    private static Map<IElementType, TextAttributesKey> keys;


    public static final TextAttributesKey NUMBER = TextAttributesKey.createTextAttributesKey("LISP.NUMERIC_LITERAL", DefaultLanguageHighlighterColors.NUMBER.getDefaultAttributes());
    public static final TextAttributesKey STRING = TextAttributesKey.createTextAttributesKey("LISP.STRING_LITERAL", DefaultLanguageHighlighterColors.STRING.getDefaultAttributes());
    public static final TextAttributesKey BAD_CHARACTER = TextAttributesKey.createTextAttributesKey("LISP.BAD_CHARACTER", HighlighterColors.BAD_CHARACTER.getDefaultAttributes());
    public static final TextAttributesKey COMMENT = TextAttributesKey.createTextAttributesKey("LISP.LINE_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT.getDefaultAttributes());
    public static final TextAttributesKey KEYWORD = TextAttributesKey.createTextAttributesKey("LISP.KEYWORD", DefaultLanguageHighlighterColors.KEYWORD.getDefaultAttributes());
    public static final TextAttributesKey SYMBOL = TextAttributesKey.createTextAttributesKey("LISP.SYMBOL", HighlighterColors.TEXT.getDefaultAttributes());

    static {
        keys = new HashMap<IElementType, TextAttributesKey>();

        keys.put(LispTypes.KEYWORDS, KEYWORD);
        keys.put(LispTypes.COMMENT, COMMENT);
        keys.put(LispTypes.BAD_CHARACTER, BAD_CHARACTER);
        keys.put(LispTypes.STRING, STRING);
        keys.put(LispTypes.NUMBER, NUMBER);
        keys.put(LispTypes.SYMBOL, SYMBOL);
    }

    @NotNull
    public Lexer getHighlightingLexer() {
        return new FlexAdapter(new LispLexer((Reader) null));
    }

    @NotNull
    public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
        return pack(keys.get(tokenType));
    }
}
